home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
dtk_demo.zip
/
SETFDATE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-12
|
3KB
|
128 lines
/* SETFDATE.C
* last mod.: 28-AUG-91
*/
#include <STDIO.H>
#include <STDLIB.H>
#include <STRING.H>
#include <L_FILE.H>
#include <L_DIR.H>
#include <L_DATE.H>
#include <L_TIME.H>
Uchar *usage = "Use: SETFDATE file_spec [month-day-year] [hour:minute]\n";
Uchar normal_file_spec[_MAX_PATH_];
Uchar date_str[16], time_str[16];
/*----------------------------*/
void main(int argc, char **argv)
{
int i, result;
Date date;
Date_format df;
Time time;
Time_format tf;
Str_ptr token;
if ( argc < 2 )
{
printf(usage);
exit(0);
}
result = normalize_path(argv[1],normal_file_spec);
if ( result < 0 )
{
printf("\nInvalid file specification.\n");
exit(1);
}
else if ( result & _PATH_EXISTS_ & _PATH_TO_DIRECTORY_ )
{
printf("\nPath leads to subdirectory.\n");
exit(2);
}
else if ( ! ( result & _PATH_EXISTS_ ) )
{
printf("\nNo files found.\n");
exit(3);
}
get_system_date(&date);
set_date_format_default(&df);
df.justify = TRUE;
df.date_separator = '-';
date_to_str(&date,&df,date_str);
printf("\nSystem date: %s",date_str);
get_system_time(&time);
set_time_format_default(&tf);
tf.hr_justified = TRUE;
tf.style = 1; /* 24-hour */
tf.components = 1; /* hr:min:sec */
time_to_str(&time,&tf,time_str);
printf("\nSystem time: %s",time_str);
for ( i=2; i<argc; i++ )
{
if ( strchr(argv[i],'-') != NULL )
{
if ( ( token = strtok(argv[i],"-") ) != NULL )
{
date.month = atoi(token);
if ( ( token = strtok(NULL,"-") ) != NULL )
{
date.day = atoi(token);
if ( ( token = strtok(NULL,"-") ) != NULL )
{
date.year = atoi(token);
if ( date.year < 1900 )
date.year += 1900;
}
}
}
}
else if ( strchr(argv[i],':') != NULL )
{
if ( ( token = strtok(argv[i],":") ) != NULL )
{
time.hour = (Uchar)atoi(token);
if ( ( token = strtok(NULL,":") ) != NULL )
time.minute = (Uchar)atoi(token);
time.second = time.hsecond = 0;
}
}
}
if ( argc > 2 )
{
date_to_str(&date,&df,date_str);
printf("\n File date: %s",date_str);
time_to_str(&time,&tf,time_str);
printf("\n File time: %s",time_str);
}
if ( !date_valid(&date) )
{
printf("\nInvalid date.\n");
exit (-9);
}
if ( !time_valid(&time) )
{
printf("\nInvalid time.\n");
exit (-10);
}
result = set_file_date_time(normal_file_spec,NULL,&date,&time);
if ( result > 0 )
printf("\n%d file%s modified.\n",
result, ( result>0 ? "s" : "" ) );
else if ( !result )
printf("\nNo files modified.\n");
else
printf("\nError %d",result);
exit(result);
}